using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.UserDomain;
//using ShivamEMR.Web.Areas.User.Models;
using ShivamEMR.Model.DataInterfaces.UsersDataInterf;
using ShivamEMR.Model;
using ShivamEMR.Web.Models;

namespace ShivamEMR.Web.Areas.User.Controllers
{   
    public class UserRightTypeController : Controller
    {
		private readonly IUserRightTypeRepository userrighttypeRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public UserRightTypeController()
        {
            userrighttypeRepository = Registry.RepositoryFactory.GetUserRightTypeRepository();
        }

        public UserRightTypeController(IUserRightTypeRepository userrighttypeRepository)
        {
			this.userrighttypeRepository = userrighttypeRepository;
        }

        //
        // GET: /UserRightType/
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        public ViewResult Index()
        {
          //  return View(userrighttypeRepository.AllIncluding(userrighttype => userrighttype.UserRights));
            return View(userrighttypeRepository.All);
        }

        //
        // GET: /UserRightType/Details/5
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        public ViewResult Details(int id)
        {
            return View(userrighttypeRepository.Find(id));
        }

        //
        // GET: /UserRightType/Create
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /UserRightType/Create
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        [HttpPost]
        public ActionResult Create(UserRightType userrighttype)
        {
            if (ModelState.IsValid) {
                userrighttypeRepository.Create(userrighttype);
                userrighttypeRepository.Save();
                return RedirectToAction("Index");
            } else {
				return View();
			}
        }
        
        //
        // GET: /UserRightType/Edit/5
 [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        public ActionResult Edit(int id)
        {
             return View(userrighttypeRepository.Find(id));
        }

        //
        // POST: /UserRightType/Edit/5
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        [HttpPost]
        public ActionResult Edit(UserRightType userrighttype)
        {
            if (ModelState.IsValid) {
                userrighttypeRepository.Update(userrighttype);
                userrighttypeRepository.Save();
                return RedirectToAction("Index");
            } else {
				return View();
			}
        }

        //
        // GET: /UserRightType/Delete/5
 [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        public ActionResult Delete(int id)
        {
            return View(userrighttypeRepository.Find(id));
        }

        //
        // POST: /UserRightType/Delete/5
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
           // userrighttypeRepository.Delete(id);
            var urtype = userrighttypeRepository.Find(id);
            userrighttypeRepository.Delete(urtype);
            userrighttypeRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

